
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>http</title>
</head>
<body>
    
    <script src="../jquery.js"></script>
    <script type="module">
         /**
         * 1.封装promise版本的请求 
         * params:{
         *      url,
         *      method,
         *      data:{},
         *      header
         * }
         * 
         * return:包含结果的promise对象(成功|失败)
         * 
         * */

    async function http({url,method="GET",data={}}) {
        console.log(url, method, data)
        return  new Promise((resolve,reject)=>{
             //异步代码   resolve成功   reject失败
             $.ajax({
                // url:url,
                url,
                method,
                data,
                success:res=>resolve(res),
                fail:err=>reject(err)
                
             })
       })
    }


       
    // let data =http({url:"http://hmajax.itheima.net/api/city?pname=河南省"})
    // console.log(data);
    
    // data.then(res=>{
    //     console.log(res);
        
    // })
    

    let data =await http({url:"http://hmajax.itheima.net/api/city?pname=河南省"})
    console.log(data);
    

    </script>

</body>
</html>